package com.lcu.student.controller;

import com.lcu.Result.Result;
import com.lcu.student.entity.Student;
import com.lcu.student.entity.Subject;
import com.lcu.student.service.SubjectService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 查询所有科目
     *
     * @return
     */
    @GetMapping("/selectSubject")
    public Result selectSubject() {
        return subjectService.selectSubject();
    }

    /**
     * 带条件的分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param subject
     * @return
     */
    @PostMapping("/selectByPage/{currentPage}/{pageSize}")
    public Result selectByPage(@PathVariable int currentPage, @PathVariable int pageSize, @RequestBody Subject subject) {
        return subjectService.selectByPage(currentPage, pageSize, subject);
    }

    /**
     * 添加数据
     *
     * @param subject
     * @return
     */
    @PostMapping("/addSubject")
    public Result addSubject(@RequestBody Subject subject) {
        return subjectService.addSubject(subject);
    }

    /**
     * 修改数据
     *
     * @param subject
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Subject subject) {
        return subjectService.updateById(subject);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable String id) {
        return subjectService.deleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        return subjectService.deleteByIds(ids);
    }
}
